WordList = ["挂了", "自习", "成绩", "学分绩", "分数", "查分", "没挂", "没有挂", "门课", "第一名", "GPA", "gpa", "悲剧", "挂科", "倒数", "考试", "INFO", "老师", "上课", "作业", "点名", "专业课", "必修课", "任选课"];
toLog = true;
var feed_num = 0;
var filter_num = 0;
$(document).ready(function(){
    //$("div.tabview > h3.title").html( $("div.tabview > h3.title").html() + "&nbsp;<a href='' class='plugin-renren-filter' alt='option'>屏蔽设置</a>" );
    //$('.plugin-renren-filter').click(function(){
    //
    //});
    FilterFeed();
    setInterval(function(){if ($("article.a-feed").length > feed_num) {FilterFeed();}}, 200);
});

function FilterFeed() {
    if (toLog) {
        console.log("Filter");
    }
    var feedlist = $("article.a-feed");
    feed_num = feedlist.length;
    var regMark = /<.+?>/g;
    for(var i=0; i<feedlist.length; i++) {
        var temp = feedlist[i];
        var feedid = temp.id;
        
        // content
        var feed_title = $("article#"+feedid+" > h3").html();
        if (feed_title == null) {
            feed_title = " ";
        }
        var feed_share_title = $("article#"+feedid+" > div.content > div.description > p.title").html();
        if (feed_share_title == null) {
            feed_share_title = " ";
        }
        var feed_share_album = $("article#"+feedid+" > div.content > div.description > p.album-name").html();
        if (feed_share_album == null) {
            feed_share_album = " ";
        }
        var feed_share_album_title = $("article#"+feedid+" > div.content > div.share-source > div.description > p.title").html();
        if (feed_share_album_title == null) {
            feed_share_album_title = " ";
        }
        var feed_share_album_description = $("article#"+feedid+" > div.content > div.share-source > div.description > p.album-name").html();
        if (feed_share_album_description == null) {
            feed_share_album_description = " ";
        }
        var feed_share_blog_title = $("article#"+feedid+" > div.content > div.share-source > div.blog-desc > p.blog-title").html();
        if (feed_share_blog_title == null) {
            feed_share_blog_title = " ";
        }
        var feed_share_blog_description = $("article#"+feedid+" > div.content > div.share-source > div.blog-desc > p.blog-description").html();
        if (feed_share_blog_description == null) {
            feed_share_blog_description = " ";
        }
        var feed_share_link_title = $("article#"+feedid+" > div.content > div.share-source > div.blog-desc > p.link-title").html();
        if (feed_share_link_title == null) {
            feed_share_link_title = " ";
        }
        var feed_share_link_description = $("article#"+feedid+" > div.content > div.share-source > div.blog-desc > p.link-description").html();
        if (feed_share_link_description == null) {
            feed_share_link_description = " ";
        }
        var feed_share_original = $("article#"+feedid+" > div.content > div.original-stauts").html();
        if (feed_share_original == null) {
            feed_share_original = " ";
        }
        
        var feed_content = feed_title + feed_share_title + feed_share_album + feed_share_blog_title + feed_share_blog_description + 
                           feed_share_link_title + feed_share_link_description + feed_share_original + feed_share_album_title + feed_share_album_description;
        
        if (feed_content != null) {
            feed_content = feed_content.replace(regMark, " ");
            var hasWord = false;
            var j=0;
            for (j=0; j<WordList.length; j++) {
                if (feed_content.search(WordList[j]) != -1) {
                    hasWord = true;
                    break;
                }
            }
            if (hasWord) {
                $("article#"+feedid).remove();
                filter_num ++;
                if (toLog) {
                    console.log("Filter out "+filter_num+" feeds due to ("+WordList[j]+")");
                    console.log("feedtitle: "+feed_content);
                }
            }
        }
    }
}
